package pub.gll.onepeas.libbase.track.manager

import android.view.View
import pub.gll.onepeas.libbase.track.ui.KKTrackerExposureLayout
import java.util.*

/**
 * <pre>
 *     @author : whg
 *     @e-mail : guanhuawei@kkworld.com
 *     @time   : 2021/11/30 10:59
 *     @desc   : 页面和曝光管理类一一对应
 *     @version: 1.0
 * </pre>
 */
internal object KKExposurePageManager {

    private val exposureMap: WeakHashMap<KKTrackerExposureLayout, KKExposureManager?> =
        WeakHashMap()

    /**
     * 获取页面对应的manager
     * @param layout KKTrackerExposureLayout
     * @return KKExposureManager?
     */
    fun getExposureManager(layout: KKTrackerExposureLayout): KKExposureManager? {
        return exposureMap[layout]
    }


    /**
     * 绑定页面的manager
     * @param layout KKTrackerExposureLayout
     */
    fun setLayoutExposureManager(layout: KKTrackerExposureLayout) {
        var kkExposureManager = exposureMap[layout]
        if (kkExposureManager == null) {
            kkExposureManager = KKExposureManager()
        }
        exposureMap[layout] = kkExposureManager
    }

    /**
     * 删除manager
     * @param layout View?
     */
    fun removeExposureManager(layout: View?) {
        layout?.let {
            if (exposureMap.contains(it)) {
                exposureMap.remove(it)
            }
        }

    }


}